#include <bits/stdc++.h>
using namespace std;

class ListNode{
public:
	ListNode* next;
	int data;
};

class Test{
public:
	ListNode *detectCycle(ListNode *head){
		ListNode* fast = head;
		ListNode* slow = head;
		bool flag = false;
		while(fast != NULL && fast ->next != NULL){
			fast = fast->next->next;
			slow = slow->next;
			if(fast == slow){
				flag = true;
				break;
			}
		}
		if(flag){
			ListNode* fast = head;
			while(fast!=slow){
				fast = fast->next;
				slow = slow->next;
			}
			return fast;
		}
		return NULL;
	}
};

int main(){
	
	
	return 0;
}
